// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.ui.web;

import org.dengues.ui.i18n.Messages;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public class URLDialog extends Dialog {

    public final static String CHANGE_SELECTION_NODE = "CHANGE_SELECTION_NODE"; //$NON-NLS-1$

    private String urlText;

    private String urlTD;

    private Composite container;

    private String title;

    private HTMLStructureComposite structureComposite;

    private HTMLBrowserComposite browserComposite;

    /**
     * Qiang.Zhang.Adolf@gmail.com URLDialog constructor comment.
     * 
     * @param parentShell
     */
    public URLDialog(Shell parentShell, String url, String title) {
        super(parentShell);
        setShellStyle(SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.MAX | SWT.MIN);
        this.urlText = url;
        this.title = title;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com URLDialog constructor comment.
     * 
     * @param parentShell
     */
    public URLDialog(Shell parentShell, String url) {
        super(parentShell);
        setShellStyle(SWT.RESIZE | SWT.MAX | SWT.MIN);
        this.urlText = url;
        title = ""; //$NON-NLS-1$
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#close()
     */
    @Override
    public boolean close() {
        return super.close();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    @Override
    protected Control createDialogArea(Composite parent) {
        container = (Composite) super.createDialogArea(parent);
        container.setLayout(new GridLayout());
        SashForm mainForm = new SashForm(container, SWT.HORIZONTAL);
        mainForm.setLayout(new GridLayout());
        mainForm.setLayoutData(new GridData(GridData.FILL_BOTH));
        createHTMLStructure(mainForm);
        createHTMLBrowser(mainForm);
        mainForm.setWeights(new int[] { 1, 3 });
        getShell().setText(title);
        return container;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "createHTMLStructure".
     * 
     * @param mainForm
     */
    private void createHTMLStructure(Composite mainForm) {
        structureComposite = new HTMLStructureComposite(mainForm);
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "createHTMLBrowser".
     * 
     * @param mainForm
     */
    private void createHTMLBrowser(Composite mainForm) {
        browserComposite = new HTMLBrowserComposite(mainForm, urlText);
        browserComposite.setHTMLStructureComposite(structureComposite);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setSize(900, 400);

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
    @Override
    protected void okPressed() {
        urlText = browserComposite.getURL();
        urlTD = structureComposite.getTdText();
        super.okPressed();
    }

    public String getUrlText() {
        return this.urlText;
    }

    /**
     * Getter for urlTD.
     * 
     * @return the urlTD
     */
    public String getUrlTD() {
        return this.urlTD;
    }
}
